//
//  ChoiceCityCollectionCell.m
//  carcareIOS
//
//  Created by 王然 on 16/8/4.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "ChoiceCityCollectionCell.h"

#define TitleL_Color (COLOR_HEXSTRING(@"#424242"))

@interface ChoiceCityCollectionCell()

@property (nonatomic , strong) UILabel * titleL;

@property (nonatomic , strong) UIImageView * cancelImageV;
@property (nonatomic , strong) UIButton * cancleBtn;

@end
@implementation ChoiceCityCollectionCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}
- (void)createUI
{
    
    CGFloat titleLY = 8;
    self.titleL = [[[[[UILabel labelWithFrame:CGRectMake(0, titleLY, 10, CELL_HEIGHT - titleLY * 2) font:Label_Font text:@"" textColor:TitleL_Color] setupOnView:self] labelResetTextAlignment:NSTextAlignmentCenter]resetBorderWidth:1 borderColor:[Theme lineColor]] resetCornerRadius:2];
    
    UIImage * cancelImage = ImageNamed(@"choiceCityCancelBtnImage");
    self.cancelImageV =[[UIImageView imageViewWithCenter:CGPointMake(self.width, titleLY) image:cancelImage] setupOnView:self];
    [self bringSubviewToFront:self.cancelImageV];
    
    self.cancleBtn = [[UIButton buttonEmptyWithFrame:CGRectMake(0, 0, cancelImage.size.width  * 2, cancelImage.size.height * 2) click:nil] setupOnView:self];
    [self.cancleBtn setCenter:self.cancelImageV.center];
    self.cancleBtn.backgroundColor = [UIColor clearColor];
    [self.cancleBtn addTarget:self action:@selector(cancleBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self bringSubviewToFront:self.cancleBtn];
}
- (void)setIsHiddenCancleBtn:(BOOL)isHiddenCancleBtn
{
    _isHiddenCancleBtn = isHiddenCancleBtn;
    [self.cancelImageV setHidden:isHiddenCancleBtn];
    [self.cancleBtn setHidden:isHiddenCancleBtn];
}
- (void)cancleBtnClick:(UIButton *)sender
{
    if (self.cancleBtnClick) self.cancleBtnClick(sender.tag);
}
- (void)reloadTitle:(NSString *)title subTitle:(NSString *)subTitle index:(NSInteger)index
{
    if ([subTitle isNotNil]) {
        NSAttributedString * attriStr1 = [[NSAttributedString attributedStringWithText:[NSString stringWithFormat:@"%@ ",title]] copyAttributedStringWithFont:Label_Font];
        NSAttributedString * attriStr2 = [[[NSAttributedString attributedStringWithText:subTitle] copyAttributedStringWithFont:FONT_DEFAULT_Light(12)] copyAttributedStringWithColor:COLOR_HEXSTRING(@"#bdbdbd")];
        [self.titleL setAttributedText:[NSAttributedString attributedStringWithAttributedStrings:@[attriStr1,attriStr2]]];
    }else [self.titleL setText:title];
    [self.titleL resetBorderWidth:1 borderColor:[title isNotNil] ? [Theme lineColor] : [UIColor clearColor]];
    self.titleL.width = self.width - Label_RIGHT ;
    
    self.cancelImageV.centerX = self.titleL.right;
    self.cancleBtn.centerX = self.titleL.right;
    self.cancleBtn.tag = index;
}
@end
